<!-- 9000系统人员登录窗口 -->
<template>
  <div>
      <el-dialog   :modelValue="dialogVisible"  title="登录窗口"  width="40%"
                  :close-on-click-modal="false" :close-on-press-escape="false"
                  :show-close="false" >

          <el-form :model="loginForm" :rules="rules" ref="loginFormRef">
            <el-form-item prop="username">
              <!-- <el-input v-model="loginForm.username" placeholder="用户名"></el-input> -->
              <el-select v-model="operid" placeholder="选择操作员" >
                <el-option
                  v-for="item in operators"
                  :key="item.operid"
                  :label="item.opername"
                  :value="item.operid"
                />
              </el-select>
            </el-form-item>
            <el-form-item prop="password">
              <el-input v-model="loginForm.password" type="password" placeholder="密码"></el-input>
            </el-form-item>
          </el-form>

        <template #footer>
          <el-button @click="handleCancel">取 消</el-button>
          <el-button type="primary" @click="handleOk">登 录</el-button>
        </template>
      </el-dialog>

  </div>
</template>

<script>

import {ElMessage} from "element-plus";
import { mapState } from 'vuex'
import request from "@/utils/drawutils/request";

export default {
  name: "DlgLogin",
  props:{ dialogVisible: Boolean },
  components:{},
  emits:[ "resLogin" ],

  mounted() {

  },
  computed:{
    ...mapState([
        'prefix',
        'operators',
        'opername',
        'operpower',
    ]),
  },
  data(){
    return{
      loginForm: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      },
      operid: "",
    }
  },
  watch: {

  },
  methods:{
    handleOk(  ){
      // console.log( "button ok: ", this.operid , this.loginForm.password)
      
      request.post( "/hg9000operator/checkpwd?" + "operid=" + this.operid +   "&pwd=" + this.loginForm.password ).then(res => {
        console.log( "9000 login: ", res  ) 
          if( res.code === "0" )
            ElMessage.error("密码错误!")
          if( res.code === "1" ){
            ElMessage.success("登录成功!")
            this.$store.commit( "setOperPower", res.data[0].operpower )
            this.$store.commit( "setOperName", res.data[0].opername )
            this.$store.commit( "setOperId", res.data[0].operid )
            // console.log( this.opername, this.operpower )
            this.$emit( "resLogin", 1 )
          }
      })
    },

    handleCancel(  ){
      this.$emit( "resLogin", 0 )
    }

  },  // end of methods

}

</script>

<style  lang="less" scoped >


</style>